package com.mvpandroiddemo.login;

import android.text.TextUtils;

import com.mvpandroiddemo.base.BasePresenter;
import com.orhanobut.logger.Logger;

public class LoginPresent extends BasePresenter<LoginActivity> implements LoginControl.ILoginPresent {

    private LoginModel loginModel;

    public LoginPresent() {
        loginModel = new LoginModel(this);
    }

    @Override
    public void initLocal() {
        String modelUserName = loginModel.initModelUserName();
        String modelPwd = loginModel.initModelPwd();
        baseView.get().initLogin(modelUserName, modelPwd);
    }


    @Override
    public void onLogin() {
        String userName = baseView.get().getUserName();
        if (TextUtils.isEmpty(userName)) {
            Logger.i("用户名称不能为空");
            return;
        }
        String pwd = baseView.get().getPwd();
        if (TextUtils.isEmpty(pwd)) {
            Logger.i("用户密码不能为空");
            return;
        }
        baseView.get().showDialog();
        loginModel.login(userName, pwd);
    }

    @Override
    public void loginSuccess() {
        Logger.i("登录成功了");
        baseView.get().hiddenDialog();
        baseView.get().startMainUI();
    }

    @Override
    public void loginFailure(String msg) {
        Logger.i("登录失败 => " + msg);
        baseView.get().hiddenDialog();

    }
}
